namespace pengpeng {
    export abstract class TextureAtlasData {
        public autoSearch: boolean;
        public scale: number;
        public width: number;
        public height: number;
        public name: string;
        public imagePath: string;
        public textures: Map<string,TextureData> = new Map();

        public constructor() {
        }

        protected _onClear(): void {
            for (let k in this.textures) {
                this.textures[k].returnToPool();
                delete this.textures[k];
            }

            this.autoSearch = false;
            this.scale = 1.0;
            this.width = 0.0;
            this.height = 0.0;
            //this.textures.clear();
            this.name = null;
            this.imagePath = null;
        }

        public abstract generateTexture(): TextureData;

        public addTexture(value: TextureData): void {
            if (value && value.name && !this.textures[value.name]) {
                this.textures[value.name] = value;
                value.parent = this;
            }
            else {
                throw new Error();
            }
        }

        public getTexture(name: string): TextureData {
            return this.textures[name];
        }

        public copyFrom(value: TextureAtlasData): void {
            this.autoSearch = value.autoSearch;
            this.scale = value.scale;
            this.width = value.width;
            this.height = value.height;
            this.name = value.name;
            this.imagePath = value.imagePath;

            for (let k in this.textures) {
                this.textures[k].returnToPool();
                delete this.textures[k];
            }

            for (let k in value.textures) {
                const texture = this.generateTexture();
                texture.copyFrom(value.textures[k]);
                this.textures[k] = texture;
            }
        }
    }

}